var __extends =
    (this && this.__extends) ||
    (function () {
      var t = function (e, a) {
        return (t =
          Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array &&
            function (t, e) {
              t.__proto__ = e;
            }) ||
          function (t, e) {
            for (var a in e)
              Object.prototype.hasOwnProperty.call(e, a) && (t[a] = e[a]);
          })(e, a);
      };
      return function (e, a) {
        function i() {
          this.constructor = e;
        }
        if ("function" != typeof a && null !== a)
          throw new TypeError(
            "Class extends value " + String(a) + " is not a constructor or null"
          );
        t(e, a),
          (e.prototype =
            null === a
              ? Object.create(a)
              : ((i.prototype = a.prototype), new i()));
      };
    })(),
  MatchArenaView = (function (t) {
    function e() {
      var e = t.call(this) || this;
      return (
        (e.matchArray = []),
        (e.rankNum = 0),
        (e.loadedNowRankState = !1),
        (e.currentYear = 0),
        (e.currentMonth = 0),
        e.btn_match_back.on(Laya.Event.CLICK, e, e.onMatchArenaMatchBack),
        e.btn_match_dengtaidoujiang.on(
          Laya.Event.CLICK,
          e,
          e.onStartDouJiangAction
        ),
        WebSocketService.addListener({
          caller: e,
          code: 1525,
          method: e.onLoadDJTData,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 1542,
          method: e.onLoadJoinDouJiangTaiData,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 1544,
          method: e.onLoadQuitDouJiangTaiData,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 1547,
          method: e.onLoadDJTRankListData,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 1546,
          method: e.onMatchMonthRankListData,
        }),
        (e.list_matchArena.vScrollBarSkin = ""),
        (e.list_matchArena.selectEnable = !0),
        e.list_matchArena.on(Laya.Event.CLICK, e, e.onListDidClickAction),
        (e.list_matchArena.renderHandler = new Laya.Handler(
          e,
          e.updateMatchItemRender
        )),
        e.btn_match_shangqi.on(Laya.Event.CLICK, e, e.onMatchRankListAction),
        e.btn_match_yuebang.on(Laya.Event.CLICK, e, e.onMatchRankListAction),
        e.btn_match_gzsm.on(Laya.Event.CLICK, e, e.OnDidClickGZSMAction),
        e.btn_match_jlsm.on(Laya.Event.CLICK, e, e.OnDidClickJLSMAction),
        e.label_upMonth.on(Laya.Event.CLICK, e, e.onUpMonthData),
        e.label_downMonth.on(Laya.Event.CLICK, e, e.onDownMonthData),
        (e.label_match_timeDown.x = 100),
        e
      );
    }
    return (
      __extends(e, t),
      (e.showMatchView = function () {
        null == this.matchV && (this.matchV = new e()),
          WebSocketService.send({ c: 1525 }),
          (this.matchV.currentPage = 0),
          (this.matchV.isloading = !1);
        var t = new Date();
        return (
          (this.matchV.spaceTime = t.getTime()),
          (this.matchV.rankNum = 0),
          (this.matchV.currentYear = new Date().getFullYear()),
          (this.matchV.currentMonth = new Date().getMonth() + 1),
          (this.matchV.label_downMonth.visible = !1),
          (this.matchV.matchState = !1),
          (this.matchV.loadedNowRankState = !1),
          (this.matchV.btn_match_shangqi.selected = !0),
          (this.matchV.btn_match_yuebang.selected = !1),
          (this.matchV.label_upMonth.visible = !1),
          (this.matchV.label_downMonth.visible = !1),
          (this.matchV.label_match_month.visible = !1),
          (this.matchV.label_match_seq.visible = !0),
          this.matchV
        );
      }),
      (e.prototype.onRefreshMatchListFn = function () {
        WebSocketService.send({ c: 1525 });
      }),
      (e.prototype.onMatchRankListAction = function (t) {
        if (
          ((this.btn_match_shangqi.selected = !1),
          (this.btn_match_yuebang.selected = !1),
          "item0" == t.target.name)
        )
          (this.btn_match_shangqi.selected = !0),
            WebSocketService.send({
              c: 1547,
              d: { aid: this.rankNum, pageNum: 0 },
            }),
            (this.label_match_seq.visible = !0),
            (this.label_upMonth.visible = !1),
            (this.label_downMonth.visible = !1),
            (this.label_match_month.visible = !1),
            (this.loadedNowRankState = !1);
        else if ("item1" == t.target.name) {
          this.btn_match_yuebang.selected = !0;
          var e = new Date().getMonth() + 1;
          WebSocketService.send({ c: 1546, d: { y: 2019, m: e, pageNum: 0 } }),
            (this.label_match_seq.visible = !1),
            (this.label_upMonth.visible = !0),
            (this.label_downMonth.visible = !1),
            (this.label_match_month.visible = !0);
        }
      }),
      (e.prototype.onUpMonthData = function () {
        this.label_downMonth.visible = !0;
        var t = this.currentYear,
          e = this.currentMonth - 1;
        0 == e && ((t = this.currentYear - 1), (e = 12)),
          WebSocketService.send({ c: 1546, d: { y: t, m: e, pageNum: 0 } }),
          (this.label_match_month.text = t + "年" + e + "月"),
          (this.currentYear = t),
          (this.currentMonth = e);
      }),
      (e.prototype.onDownMonthData = function () {
        var t = this.currentYear,
          e = this.currentMonth + 1;
        if (this.currentYear >= new Date().getFullYear()) {
          if (this.currentMonth >= new Date().getMonth() + 1)
            return void (this.label_downMonth.visible = !1);
        } else
          13 == e &&
            ((this.currentYear += 1),
            (this.currentMonth = 1),
            (e = this.currentMonth),
            (t = this.currentYear));
        WebSocketService.send({ c: 1546, d: { y: t, m: e, pageNum: 0 } }),
          (this.label_match_month.text = t + "年" + e + "月"),
          (this.currentYear = t),
          (this.currentMonth = e),
          this.currentYear >= new Date().getFullYear() &&
            this.currentMonth >= new Date().getMonth() + 1 &&
            (this.label_downMonth.visible = !1);
      }),
      (e.prototype.onListDidClickAction = function (t) {
        if ("" != t.target.name && t.target.name) {
          var e = this.matchArray[this.list_matchArena.selectedIndex];
          t.target.mouseX > 235
            ? this.btn_match_shangqi.selected
              ? MatchHistoryDialog.openMatchHistoryDialog(e, !0, this.rankNum)
              : MatchHistoryDialog.openMatchHistoryDialog(e, !1, this.rankNum)
            : FriendsDetailDialog.showFriendDialog(e.id, !0);
        }
      }),
      (e.prototype.onStartDouJiangAction = function (t) {
        WebSocketService.send({ c: 1525 }),
          WebSocketService.send({ c: 1542 }),
          (this.matchState = !0);
      }),
      (e.prototype.onLoadDJTRankListData = function (t) {
        if (0 == t.code) {
          this.matchArray = [];
          var e = void 0;
          if (this.currentPage >= 1) {
            if (0 == t.list.length) return void this.currentPage--;
            for (var a = 0; a < t.list.length; a++) {
              var i = t.list[a];
              this.matchArray.push(i), (this.dataSource = []);
            }
          } else (this.matchArray = t.list), (this.dataSource = []);
          this.isloading = !1;
          for (var n = 0; n < this.matchArray.length; n++) {
            var h = this.matchArray[n];
            (e = {
              label_match_index: { text: this.dealMatchRanking(h.r) },
              label_match_name: { text: h.n },
              label_match_jifen: { text: " 积分" + h.s },
            }),
              this.dataSource.push(e);
          }
          this.list_matchArena.dataSource = this.dataSource;
        } else ToastView.toastView(t.msg);
      }),
      (e.prototype.dealMatchRanking = function (t) {
        return "1" == t ? "冠军" : "2" == t ? "亚军" : "3" == t ? "季军" : t;
      }),
      (e.prototype.onLoadDJTData = function (t) {
        0 == t.code &&
          ("1" == t.data.s
            ? ((this.label_match_timeDown.visible = !0),
              (this.label_match_time_title.text = ""),
              (this.timeDiff = t.data.t),
              Laya.timer.loop(1e3, this, this.timerCountDownMatchFn),
              (this.btn_match_shangqi.label = "本届(" + t.data.id + ")"),
              (this.btn_match_dengtaidoujiang.visible = !0),
              (this.btn_match_shangqi.y = 180),
              (this.btn_match_yuebang.y = 180),
              "0" == t.data.i
                ? (this.btn_match_dengtaidoujiang.label = "登台斗将")
                : "1" == t.data.i
                ? (this.btn_match_dengtaidoujiang.visible = !1)
                : "2" == t.data.i &&
                  (this.btn_match_dengtaidoujiang.label = "继续匹配"),
              (this.isStartMatchState = !0))
            : ((this.timeDiff = t.data.t),
              Laya.timer.loop(1e3, this, this.timerCountDownMatchFn),
              (this.label_match_time_title.text = ""),
              (this.btn_match_dengtaidoujiang.visible = !1),
              (this.btn_match_shangqi.y = 150),
              (this.btn_match_yuebang.y = 150),
              (this.btn_match_shangqi.label = "上届(" + t.data.id + ")"),
              (this.isStartMatchState = !1)),
          this.btn_match_shangqi.selected &&
            0 == this.loadedNowRankState &&
            (WebSocketService.send({
              c: 1547,
              d: { aid: t.data.id, pageNum: 0 },
            }),
            (this.loadedNowRankState = !0)),
          (this.rankNum = t.data.id),
          t.data.r < 0
            ? (this.label_match_seq.text = "您当前暂未有排名")
            : (this.label_match_seq.text = "您当前的第" + t.data.r + "名"));
      }),
      (e.prototype.timerCountDownMatchFn = function () {
        this.timeDiff--;
        var t = 0,
          e = 0,
          a = 0,
          i = 0;
        (t = Math.floor(this.timeDiff / 86400)),
          (e = Math.floor((this.timeDiff % 86400) / 3600)),
          (a = Math.floor((this.timeDiff % 3600) / 60)),
          (i = Math.floor(this.timeDiff % 60)),
          t <= 0 && e <= 0 && a <= 0 && i <= 1
            ? (Laya.timer.clear(this, this.timerCountDownMatchFn),
              (this.label_match_timeDown.text = "请稍等..."))
            : i % 10 == 0
            ? (Laya.timer.clear(this, this.timerCountDownMatchFn),
              WebSocketService.send({ c: 1525, d: null }),
              (this.label_match_timeDown.text = this.dealTimeDataWithParams(
                t,
                e,
                a,
                i
              )))
            : (this.label_match_timeDown.text = this.dealTimeDataWithParams(
                t,
                e,
                a,
                i
              ));
      }),
      (e.prototype.dealTimeDataWithParams = function (t, e, a, i) {
        var n = "0秒";
        t > 0
          ? (n = t + "天" + e + "小时" + a + "分" + i + "秒")
          : e > 0
          ? (n = e + "小时" + a + "分" + i + "秒")
          : a > 0
          ? (n = a + "分" + i + "秒")
          : i > 0 && (n = i + "秒");
        var h = "";
        return (
          (h = this.isStartMatchState ? "后结束斗将" : "后开启斗将"), n + h
        );
      }),
      (e.prototype.onMatchMonthRankListData = function (t) {
        if (0 == t.code) {
          this.matchArray = [];
          var e = void 0;
          if (this.currentPage >= 1) {
            if (0 == t.list.length) return void this.currentPage--;
            for (var a = 0; a < t.list.length; a++) {
              var i = t.list[a];
              this.matchArray.push(i), (this.dataSource = []);
            }
          } else (this.matchArray = t.list), (this.dataSource = []);
          this.isloading = !1;
          for (var n = 0; n < this.matchArray.length; n++) {
            var h = this.matchArray[n];
            (e = {
              label_match_index: { text: h.r },
              label_match_name: { text: h.n },
              label_match_jifen: { text: " 积分" + h.s },
            }),
              this.dataSource.push(e);
          }
          this.list_matchArena.dataSource = this.dataSource;
        } else ToastView.toastView(t.msg);
      }),
      (e.prototype.onLoadMoreData = function (t) {
        var e = t / this.list_matchArena.scrollBar.max,
          a = new Date(),
          i = !1;
        if (
          (a.getTime() - this.spaceTime >= 3e3 && (i = !0),
          1 == e && 0 == this.isloading && i)
        )
          return (
            (this.isloading = !0),
            (this.currentPage = 2),
            WebSocketService.send({
              c: 1447,
              d: { "": 2, pageNum: this.currentPage },
            }),
            void (this.spaceTime = a.getTime())
          );
      }),
      (e.prototype.onLoadJoinDouJiangTaiData = function (t) {
        (this.matchState = !1),
          0 == t.code
            ? ((this.label_match_time_title.text =
                "当前斗将台人数：" + t.data + "人"),
              (this.label_match_timeDown.visible = !1),
              MatchOtherDialog.showMatchNormalDialog(
                "正在匹配对手(60s)...",
                this,
                this.onPiPeiDuiShouFunction,
                this.onQuitMatchFunction
              ))
            : 1e4 == t.code
            ? MatchOtherDialog.closeMatch()
            : ToastView.toastView(t.msg);
      }),
      (e.prototype.onPiPeiDuiShouFunction = function () {
        WebSocketService.send({ c: 1542 }), WebSocketService.send({ c: 1525 });
      }),
      (e.prototype.onQuitMatchFunction = function () {
        WebSocketService.send({ c: 1544 }), WebSocketService.send({ c: 1525 });
      }),
      (e.prototype.onLoadQuitDouJiangTaiData = function (t) {}),
      (e.prototype.OnDidClickGZSMAction = function () {
        var t = RulesView.showCaslRuleView("doujiangtaiGZSM");
        (t.y = 0), Laya.stage.addChild(t);
      }),
      (e.prototype.OnDidClickJLSMAction = function () {
        var t = RulesView.showCaslRuleView("doujiangtaiJLSM");
        (t.y = 0), Laya.stage.addChild(t);
      }),
      (e.prototype.updateMatchItemRender = function (t, e) {
        if (!(e > this.matchArray.length)) {
          var a = t.getChildByName("label_match_index");
          t.getChildByName("label_match_name"),
            t.getChildByName("label_match_jifen");
          a.color =
            0 == e
              ? "#FFFF00"
              : 1 == e
              ? "#c0c0c0"
              : 2 == e
              ? "#CDAF95"
              : "#FFFFFF";
        }
      }),
      (e.prototype.onMatchArenaMatchBack = function () {
        WebSocketService.send({ c: 1544 }),
          Laya.timer.clear(this, this.onRefreshMatchListFn),
          Laya.timer.clear(this, this.timerCountDownMatchFn),
          Laya.timer.clearAll(this),
          this.removeSelf();
      }),
      e
    );
  })(ui.ChallengeBattle.MatchArenaViewUI);
